//
//  UIImage+scale.swift
//  photoSelector
//
//  Created by 大波 on 16/3/11.
//  Copyright © 2016年 zhaojin. All rights reserved.
//

import UIKit

extension UIImage {
    
    func scaleImage(newWidth: CGFloat = 300) -> UIImage {
        
        let newHeight = newWidth * size.height / size.width
        
        UIGraphicsBeginImageContext(CGSize(width: newWidth, height: newHeight))
        
        drawInRect(CGRect(origin: CGPointZero, size: CGSize(width: newWidth, height: newHeight)))
        
        let image = UIGraphicsGetImageFromCurrentImageContext()
        
        UIGraphicsEndImageContext()
        
        return image
    }
}
